using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using hontop.DBLayer;
using hontop;

namespace hontop.FormLayer
{
    public partial class DayDetail : Form
    {
        private DateTime day;
        private bool isDayChanged = false;
        public DayDetail()
        {
            InitializeComponent();
            this.monthCalendar1.Visible = false;
        }

        private void lblToday_Click(object sender, EventArgs e)
        {
            this.monthCalendar1.Visible = true;
        }

        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            this.isDayChanged = true;
            this.day = e.Start;
            this.monthCalendar1.Visible = false;
            this.lblDate.Text = e.Start.ToShortDateString();
            //BtnQuery_Click(null, null);
        }

        private void BtnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                if (!this.isDayChanged)
                    this.dataGridView1.DataSource = Sell.GetDayDetail(DateTime.Now);
                else
                    this.dataGridView1.DataSource = Sell.GetDayDetail(day);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, MyTool.Caption);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void DayDetail_Load(object sender, EventArgs e)
        {
            this.monthCalendar1.BackColor = System.Drawing.SystemColors.Info;
            this.monthCalendar1.ForeColor = System.Drawing.Color.FromArgb(
                                     ((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(192)));
            this.monthCalendar1.TitleBackColor = System.Drawing.Color.Purple;
            this.monthCalendar1.TitleForeColor = System.Drawing.Color.Yellow;
            this.monthCalendar1.TrailingForeColor = System.Drawing.Color.FromArgb(
                                     ((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(0)));
            //BtnQuery_Click(null, null);
            this.lblDate.Text = DateTime.Now.ToShortDateString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                MyTool.DataTableToExcel((DataTable)this.dataGridView1.DataSource);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, MyTool.Caption);
            }
        }
    }
}